 use "$data\women_analysis.dta", clear
 
tab ITTanalysis, gen(treatment)
rename treatment1 control
rename treatment2 treated
lab var control "dummy for control women"
lab var treated "dummy for treated women"
bysort HHID: gen HHIDrepeat=_N
lab var HHIDrepeat "no. of learners in a HH"
sort HHIDrepeat
unique HHID if HHIDrepeat>1
replace treated=2 if treated==0
sort HHID treated
bysort HHID: replace treated=treated[1]
replace treated=0 if treated==2
replace control=2 if control==0
sort HHID control
bysort HHID: replace control=control[1]
replace control=0 if control==2
egen treatcontrolsameHH=rowtotal(treated control)
lab var treatcontrolsameHH "HHs with and w/o mixed treatment status women"
lab define treatcontrol 1 "HHs w/o mixed status" 2 "HHs with mixed status"
lab values treatcontrolsameHH treatcontrol
replace treatcontrolsameHH=0 if treatcontrolsameHH==1
replace treatcontrolsameHH=1 if treatcontrolsameHH==2
lab define samehh 0 "HHs w/o mixed status" 1 "HHs with mixed status"
lab values treatcontrolsameHH samehh
replace anyhelp=0 if pid_helpedinhome=="T"
gen tutor=0 if anyhelp!=.
replace tutor=1 if pid_helpedinhome=="T"

 
global controlkid childageyears female birthorder
global controlwoman mbase_ageyears  fdstotal rantime ranerror numberkids
global controlhh land members adults mbase_electrified  mbase_OB mbase_scheduled


*****Table B.4 Panel A			
balancetable (mean) (mean if treatcontrolsameHH==1) (mean if treatcontrolsameHH==0) (diff treatcontrolsameHH) $controlkid if ITTanalysis==0 & childageyears<=16 using "$results\TableB4PanelA.xls", ///
            ctit("Full sample" "Mixed status HHs" "Control only HHs" "Difference") leftctitle("Child level controls") ///
			vce(cluster learnerid) varlabels fe(strata) nonumbers replace

*****Table B.4 Panel B			
balancetable (mean) (mean if treatcontrolsameHH==1) (mean if treatcontrolsameHH==0) (diff treatcontrolsameHH) $controlwoman if ITTanalysis==0 & sequence==1 using "$results\TableB4PanelB.xls", ///
            ctit("Full sample" "Mixed status HHs" "Control only HHs" "Difference") leftctitle("Woman level controls") ///
			vce(robust) varlabels fe(strata) nonumbers replace
			
*****Table B.4 Panel C					
balancetable (mean) (mean if treatcontrolsameHH==1) (mean if treatcontrolsameHH==0) (diff treatcontrolsameHH) $controlhh if ITTanalysis==0 & sequence==1 using "$results\TableB4PanelC.xls", ///
            ctit("Full sample" "Mixed status HHs" "Control only HHs" "Difference") leftctitle("HH level controls") ///
			vce(robust) varlabels fe(strata) nonumbers replace

exit
